package kr.hkit.powerjava.chapter16; //424페이지 lab2

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

class MyCounter extends JFrame implements ActionListener {

	private JLabel[] labels;
	private int[] numbers;
	private JButton button;
	private JLabel labels_result;
	

	public MyCounter() throws HeadlessException {
		
		setTitle("My Game");
		setSize(500,300);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setLayout(new GridLayout(2,1,0,0));
		
		JPanel panel = new JPanel();
		panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
		
		labels = new JLabel[3];
		numbers = new int[3];
		
		for (int i=0; i<3; i++) {
			labels[i] = new JLabel("" + numbers[i]);
			labels[i].setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 100));
			labels[i].setSize(100, 100);
			labels[i].setLocation(100 + 100 * i, 20);
			panel.add(labels[i]);
		}

		
		JPanel panel2 = new JPanel();
		
		button = new JButton("스핀");
		button.setSize(250, 50);
		button.setLocation(100, 150);
		panel2.add(button);
		button.addActionListener(this);

		
		
		JPanel panel3 = new JPanel();
		labels_result = new JLabel();
		labels_result.setText("득점 점수: ");
		panel3.add(labels_result);
		
		add(panel);
		add(panel2);
		add(panel3);
	
		setVisible(true);
		
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		for (int i = 0; i<3; i++) {
			numbers[i] = (int) (Math.random()*10);
			labels[i].setText(""+numbers[i]);
		}
		if (numbers[0] == numbers[1] || numbers[1]==numbers[2] || numbers[0]==numbers[2]) {
			labels_result.setText("득점 점수: " + numbers[0]+numbers[1]+numbers[2]);
		}
	}
}


public class Lab_2 {
	public static void main(String[] args) {
		new MyCounter();
	}
}
